/**
 * create by young (young2f@outlook.com) on 2020/12/4
 */
'use strict';
const model = require('../base/tModelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmcBus');
  const json = {
    salesman: {
      type: String, _type: 'string', title: '业务员', required: true, enableArea: [ 'table', 'search' ]
    },
    code: {
      type: String, _type: 'code', title: '编码', required: true, enableArea: [ 'search' ]
    },
    records: {
      type: Array, _type: 'array', title: '出差记录', enableArea: [ 'search' ],
      cols: [ {
        key: 'outDate', type: Date, _type: 'date', title: '出差日期', required: true, enableArea: [ 'search' ]
      },
        {
          key: 'matter', type: String, _type: 'string', title: '事由', required: true, enableArea: [ 'search' ]
        },
        {
          key: 'travelFee', type: Number, _type: 'number', title: '交通费', enableArea: [ 'search' ]
        },
        {
          key: 'stayFee', type: Number, _type: 'number', title: '住宿费', enableArea: [ 'search' ]
        },
        {
          key: 'subsidy', type: Number, _type: 'number', title: '伙食补助', enableArea: [ 'search' ]
        },
        {
          key: 'other', type: Number, _type: 'number', title: '其它', enableArea: [ 'search' ]
        } ]
    },

    collectionMan: {
      type: String, _type: 'string', title: '领款人', enableArea: ['table', 'search' ]
    },
    payDate: {
      type: Date, _type: 'date', title: '付款日期', enableArea: ['table', 'search' ]
    },
    factSalesman: {
      type: String, _type: 'string', title: '实际业务员', enableArea: ['table', 'search' ]
    },
    division: {
      type: String, _type: 'select', title: '客户类型', options: [
        '新客户',
        '老客户',
        '公差',
      ], enableArea: [ 'table','search' ]
    },
    count: {
      type: Number, _type: 'number', title: '合计', enableArea: ['table', 'search' ]
    },
    fileList: { type: Array, _type: 'fileList', title: '图片列表' },
  };
  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  return connect.model('DicReimburse', _schema);
};
